//@Auth:zdl
package mongo

import (
	"github.com/gogf/gf/g/os/glog"
	"gopkg.in/mgo.v2"
	"time"
)

var (
	C *mgo.Collection
	D *mgo.Database
)

func Init() {
	/*	session, err := mgo.Dial(g.Config().GetString("mongodb.addr"))
		if err != nil {
			glog.Error(err)
			return
		}
		// Optional. Switch the session to a monotonic behavior.
		session.SetMode(mgo.Monotonic, true)
		D = session.DB(g.Config().GetString("mongodb.db"))
		C = D.C(g.Config().GetString("mongodb.collection"))*/
}

func To(docs ...interface{}) {
	data := &struct {
		Info []interface{} `json:"info"`
		Time time.Time     `json:"time"`
	}{
		Time: time.Now().Local(),
		Info: append(make([]interface{}, 0), docs...),
	}
	if err := C.Insert(data); err != nil {
		glog.Error(err, "=>", data)
	}
}
